﻿using AutoMapper;
using ManagementApi.Models.System.Role;
using Modules.Cms;
using Modules.System.Role;
using Modules.System.User;
using PmSoft;

namespace ManagementApi.Models.Cms
{
    public class CmsCustomDto
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        public int CreateUserId { get; set; }

        /// <summary>
        /// 创建人名称
        /// </summary>
        public string CreateUserName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDt { get; set; }

        /// <summary>
        /// 更新人ID
        /// </summary>
        public int UpdateUserId { get; set; }

        /// <summary>
        /// 更新人名称
        /// </summary>
        public string UpdateUserName { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateDt { get; set; }

        /// <summary>
        /// 删除标识
        /// </summary>
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 客户姓名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 客户电话
        /// </summary>
        public string Phone { get; set; }
        /// <summary>
        /// 身份证号
        /// </summary>
        public string CardNo { get; set; }
        /// <summary>
        /// 区域id
        /// </summary>
        public int AreaId { get; set; }

        /// <summary>
        /// 客户地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 归属经销商id
        /// </summary>
        public int DealerId { get; set; }

        #region 扩展字段
        public string DealerName { get; set; }
        #endregion
    }

    public static partial class CmsCustomExceptions
    {
        public static CmsCustomDto AsDto(this Modules.Cms.Entitys.CmsCustom entity)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            var cmsDealerService = ServiceAccessor.GetService<CmsDealerService>();
            CmsCustomDto dto = new CmsCustomDto();
            dto.DealerName = cmsDealerService.Get(entity.DealerId)?.Name ?? "";
            mapper.Map(entity, dto);
            return dto;

        }
    }
}
